<?php require_once('includes/classes/core.php');?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>MoneyMan</title>
	<style type="text/css">
		.tdstyle{
			text-align: left;
			vertical-align:middle;
			font-size: 12px;
		}
		td{
			font-size: 12px;
		}
    </style>
</head>
<body style="width: 600px; margin: auto;">
<div style="float: left">
    <table style="margin: 0; padding: 0;">
        <tr style="margin: 0; padding: 0;">
            <td colspan="3" style="margin: 0; padding: 0;">
                <img src="media/uploads/images/client/0.jpg" alt="" height="200" width="200" style="margin: 0; padding: 0;"/>
            </td>
        </tr>
    </table>
</div>
<div style="float: left; width: 350px; margin-left: 20px;">    
        <?php 
        $name = $_REQUEST['name'];
        $res_pers = mysql_fetch_array(mysql_query("
                    SELECT 	tin,
            				address,
            				home_number,
            				mobile_number,
            				position.`person_position`,
                            persons.id
                    FROM    persons
                    JOIN    position ON persons.position = position.id
                    WHERE   persons.`name` = '$name'
                                            "));
        ?>
        <table style="width: 100%;">
        <tr>
            <td style="width: 125px; text-align: center; color: #06A; font-weight: bold; font-size: 13px;" colspan="2">ოპერატორი</td>  
        </tr>
        <tr>
            <td class="tdstyle" style="width: 150px;">სახელი, გვარი:</td>
            <td ><?php echo $_REQUEST['name'];?></td>
        </tr>
        <tr>
            <td class="tdstyle">პირადი ნომერი:</td>
            <td ><?php echo $res_pers['tin'];?></td>
        </tr>
        <tr>
            <td class="tdstyle">თანამდებობა:</td>
            <td ><?php echo $res_pers['person_position'];?></td>
        </tr>
        <tr>
            <td class="tdstyle">მისამართი:</td>
            <td ><?php echo $res_pers['address'];?></td>
        </tr>
        <tr>
            <td class="tdstyle">სახლის ტელ:</td>
            <td ><?php echo $res_pers['home_number'];?></td>
        </tr>
        <tr>
            <td class="tdstyle">მობილური ტელ:</td>
            <td ><?php echo $res_pers['mobile_number'];?></td>
        </tr>
        <tr>
            <td class="tdstyle">შენიშვნა:</td>
            <td ></td>
        </tr>
    </table>

    <table style="width: 100%; margin-top: 10px;">
        
        <tbody class="report_info">
            <tr>
                <td style="width: 125px; text-align: center; color: #06A; font-weight: bold; font-size: 13px;" colspan="2">ზოგადი ინფო</td>
                
            </tr>
            <tr>
            <?php 
            $name = $_REQUEST['name'];
            $start_time = $_REQUEST['start_time'];
            $end_time = $_REQUEST['end_time'];
            $res = mysql_fetch_array(mysql_query("
                        SELECT SUM(TIMESTAMPDIFF(MINUTE,person_work_graphic.`start`,person_work_graphic.`end`))
                        FROM person_work_graphic
                        WHERE `person_id` = '$res_pers[id]' AND DATE(person_work_graphic.`start`) >= '$start_time' AND DATE(person_work_graphic.`end`) <= '$end_time'
                                                "));
            ?>
                <td class="tdstyle" style="width: 150px;">გეგმიური სთ-ები:</td>
                <td><?php echo $res[0].' წუთი';?></td>
            </tr>
            <tr>
            <?php 
            $name = $_REQUEST['name'];
            $start_time = $_REQUEST['start_time'];
            $end_time = $_REQUEST['end_time'];
            $res = mysql_fetch_array(mysql_query("  SELECT SUM(TIMESTAMPDIFF(MINUTE,worker_action.start_date,worker_action.end_date)),
                                                    worker_action.start_date,
                                                    worker_action.end_date
                                                    FROM worker_action
                                                    WHERE `person_id` = '$res_pers[id]' AND DATE(start_date) >= '$start_time' AND DATE(end_date) <= '$end_time'"));
            ?>
                	<td class="tdstyle">იმუშავა:</td>
                    <td><?php echo $res[0].' წუთი';?></td>
            </tr>
            
            <!-- tr>
                   <td class="tdstyle">გაცდენილი სთ-ები:</td>
                   <td><?php echo rand(1, 3).' საათი'; ?></td>
            </tr-->
            <tr>
            <?php 
            $name = $_REQUEST['name'];
            $start_time = $_REQUEST['start_time'];
            $end_time = $_REQUEST['end_time'];
            $res_total_inc = mysql_fetch_array(mysql_query("
                SELECT SUM(asterisk_incomming.duration)
                FROM asterisk_incomming
                JOIN crystal_users ON asterisk_incomming.user_id = crystal_users.id
                WHERE crystal_users.`name`='$name'
                and asterisk_incomming.dst_queue=2392200
                AND asterisk_incomming.disconnect_cause != 'ABANDON'
                AND DATE(asterisk_incomming.call_datetime) >= '$start_time'
                AND DATE(asterisk_incomming.call_datetime) <= '$end_time'
                "));
            $res_total_out = mysql_fetch_array(mysql_query("
                SELECT SUM(asterisk_outgoing.duration)
                FROM asterisk_outgoing
                JOIN crystal_users ON asterisk_outgoing.user_id = crystal_users.id
                WHERE crystal_users.`name`='$name'
                AND DATE(asterisk_outgoing.call_datetime) >= '$start_time'
                AND DATE(asterisk_outgoing.call_datetime) <= '$end_time'
                "));
            
            $res_res_total = $res_total_inc[0] + $res_total_out[0]
            ?>
                   <td class="tdstyle">ისაუბრა სულ:</td>
                   <td><?php echo $res_res_total.' წუთი'; ?></td>
            </tr>
            <tr>
                   <td style="text-align: right;"><i>შემომავალი ზარზე:</i></td>
                   <td><?php echo $res_total_inc[0].' წუთი'; ?></td>
            </tr>
            <tr>
                   <td style="text-align: right;"><i>გამავალ ზარზე:</i></td>
                   <td><?php echo $res_total_out[0].' წუთი'; ?></td>
            </tr>
            <tr>
            
                   <td class="tdstyle">დატვირთვა:</td>
                   <td><?php echo ROUND((($res_res_total/$res[0])*100),2).' %'; ?></td>
            </tr>
        </tbody>
    </table>
    
<table style="margin-top: 10px; width: 100%;">
    <tbody id="answer_call_info">
        <tr> 
          <td style="width: 180px; text-align: center; color: #06A; font-weight: bold; font-size: 13px;" colspan="2">გამავალი ზარები</td>
        </tr>
        <tr> 
        <?php 
        $name = $_REQUEST['name'];
        $start_time = $_REQUEST['start_time'];
        $end_time = $_REQUEST['end_time'];
        $reso = mysql_fetch_array(mysql_query("SELECT  COUNT(*) ,
                                        			  COUNT(*) ,
                                                     SEC_TO_TIME((SUM(duration))/COUNT(*)),
                                                     SEC_TO_TIME((wait_time/COUNT(*)))            
                                        FROM `asterisk_outgoing`
                                        JOIN crystal_users ON asterisk_outgoing.user_id = crystal_users.id
                                        WHERE crystal_users.`name`='$name'
                                        AND DATE(asterisk_outgoing.call_datetime) >= '$start_time'
                                        AND DATE(asterisk_outgoing.call_datetime) <= '$end_time'
                                                "));
        ?>
          <td class="tdstyle" style="width: 150px;">სულ:</td>
          <td><?php echo $reso[0]; ?> ზარი</td>
        </tr>
        <tr> 
          <td class="tdstyle">ნაპასუხები:</td>
          <td><?php echo $reso[1]; ?> ზარი</td>
        </tr>
        <tr>        
          <td class="tdstyle">საშ. ხანგრძლივობა:</td>
          <td><?php echo $reso[2]; ?>წამი</td>
        </tr>
        <tr>         
          <td class="tdstyle">ლოდინის საშ. ხანგრძლივობა:</td>
          <td><?php echo $reso[3]; ?>წამი</td>
        </tr>
    </tbody>
</table>

<table style="width: 100%; margin-top: 10px;">
    <tbody id="answer_call_info">
    <tr> 
      <td style="width: 180px; text-align: center; color: #06A; font-weight: bold; font-size: 13px;" colspan="2">შემომავალი ზარები</td>
    </tr>
    <tr>
    <?php 
        $name = $_REQUEST['name'];
        $start_time = $_REQUEST['start_time'];
        $end_time = $_REQUEST['end_time'];
        $res1 = mysql_fetch_array(mysql_query("
                                            SELECT COUNT(*)
                                            FROM asterisk_incomming
                                            JOIN crystal_users ON asterisk_incomming.user_id = crystal_users.id
                                            WHERE crystal_users.`name`='$name'
                                            and asterisk_incomming.dst_queue='2392200'
                                            AND asterisk_incomming.disconnect_cause != 'ABANDON'
                                            AND DATE(asterisk_incomming.call_datetime) >= '$start_time'
                                            AND DATE(asterisk_incomming.call_datetime) <= '$end_time'
                                            "));
    ?> 
      <td class="tdstyle" style="width: 150px;">ნაპასუხები</td>
      <td><?php echo $res1[0].' ზარი'; ?></td>
    </tr>
    <tr> 
    <?php 
        $name = $_REQUEST['name'];
        $start_time = $_REQUEST['start_time'];
        $end_time = $_REQUEST['end_time'];
        $res = mysql_fetch_array(mysql_query("
                                            SELECT COUNT(*)
                                            FROM incomming_call
                                            JOIN asterisk_incomming ON asterisk_incomming.source = incomming_call.phone AND DATE(asterisk_incomming.call_datetime) = DATE(incomming_call.date)																
                                            JOIN crystal_users ON asterisk_incomming.user_id = crystal_users.id
                                            WHERE crystal_users.`name`='ბაზაძე ნათია'
                                            and asterisk_incomming.dst_queue='2392200'
                                            AND asterisk_incomming.disconnect_cause != 'ABANDON'
                                            AND DATE(asterisk_incomming.call_datetime) >= '$start_time'
                                            AND DATE(asterisk_incomming.call_datetime) <= '$end_time'
                                            "));
    ?> 
      <td class="tdstyle">დამუშავებული</td>
      <td><?php echo $res[0].' ზარი'; ?></td>
    </tr>
    <tr>
      <td class="tdstyle">დაუმუშავებელი:</td>
      <td><?php echo $res1[0]-$res[0].' ზარი'; ?></td>
    </tr>
    <tr>
     <?php 
            $name = $_REQUEST['name'];
            $start_time = $_REQUEST['start_time'];
            $end_time = $_REQUEST['end_time'];
            $res = mysql_fetch_array(mysql_query("  
                                                    SELECT (SUM(asterisk_incomming.duration)/COUNT(*))
                                                    FROM asterisk_incomming
                                                    JOIN crystal_users ON asterisk_incomming.user_id = crystal_users.id
                                                    WHERE crystal_users.`name`='$name'
                                                    AND asterisk_incomming.disconnect_cause != 'ABANDON'
                                                    AND DATE(asterisk_incomming.call_datetime) >= '$start_time'
                                                    AND DATE(asterisk_incomming.call_datetime) <= '$end_time'
                                                ")); 
            ?>
      <td class="tdstyle">საშ. ხანგრძლივობა:</td>
      <td><?php echo $res[0].' წამი'; ?></td>
    </tr>
    <tr>
    <?php 
            $name = $_REQUEST['name'];
            $start_time = $_REQUEST['start_time'];
            $end_time = $_REQUEST['end_time'];
            $res = mysql_fetch_array(mysql_query("  
                                                    SELECT ( SUM(asterisk_incomming.wait_time)/COUNT(*) )
                                                    FROM asterisk_incomming
                                                    JOIN crystal_users ON asterisk_incomming.user_id = crystal_users.id
                                                    WHERE crystal_users.`name`='$name'
                                                    AND asterisk_incomming.disconnect_cause != 'ABANDON'
                                                    AND DATE(asterisk_incomming.call_datetime) >= '$start_time'
                                                    AND DATE(asterisk_incomming.call_datetime) <= '$end_time'
                                                ")); 
            ?>
      <td class="tdstyle">ლოდინის საშ. ხანგრძლივობა:</td>
      <td><?php echo $res[0].' წამი'; ?></td>
    </tr>
    </tbody>
</table>

<table style="margin-top: 10px; width: 100%;">
    <tbody id="disconnection_cause_unanswer">
    <tr>
    	<td colspan="3" style="text-align: center; color: #06A; font-weight: bold; font-size: 13px;">კავშირის გაწყვეტის მიზეზი</td>
    </tr>
    <tr>
    <?php 
            $name = $_REQUEST['name'];
            $start_time = $_REQUEST['start_time'];
            $end_time = $_REQUEST['end_time'];
            $res = mysql_fetch_array(mysql_query("  
                                                  	SELECT COUNT(*)
		                                            FROM asterisk_incomming
		                                            JOIN crystal_users ON asterisk_incomming.user_id = crystal_users.id
		                                            WHERE crystal_users.`name`='$name'
		                                            and asterisk_incomming.dst_queue='2392200'
                                                    AND asterisk_incomming.disconnect_cause != 'ABANDON'
		                                            AND DATE(asterisk_incomming.call_datetime) >= '$start_time'
		                                            AND DATE(asterisk_incomming.call_datetime) <= '$end_time'
													AND asterisk_incomming.disconnect_cause='COMPLETECALLER'  
                                                ")); 
            ?>
      <td class="tdstyle" style="width: 150px;">აბონენტმა გათიშა:</td>
      <td><?php echo $res[0].' ზარი'; ?></td>
      <td></td>
    </tr>
    <tr>
    <?php 
            $name = $_REQUEST['name'];
            $start_time = $_REQUEST['start_time'];
            $end_time = $_REQUEST['end_time'];
            $res = mysql_fetch_array(mysql_query("  
                                                  	SELECT COUNT(*)
		                                            FROM asterisk_incomming
		                                            JOIN crystal_users ON asterisk_incomming.user_id = crystal_users.id
		                                            WHERE crystal_users.`name`='$name'
		                                            and asterisk_incomming.dst_queue='2392200'
                                                    AND asterisk_incomming.disconnect_cause != 'ABANDON'
		                                            AND DATE(asterisk_incomming.call_datetime) >= '$start_time'
		                                            AND DATE(asterisk_incomming.call_datetime) <= '$end_time'
													AND asterisk_incomming.disconnect_cause='COMPLETEAGENT'  
                                                ")); 
            ?> 
      <td class="tdstyle">აბონენტმა გათიშა:</td>
      <td><?php echo $res[0].' ზარი'; ?></td>
      <td></td>
    </tr>
    </tbody>
</table>

<table style="margin-top: 10px; width: 100%;" >
<tbody id="service_level">
                <tr> 
                    <td colspan="4" style="text-align: center; color: #06A; font-weight: bold; font-size: 13px;">მომსახურების დონე(Service Level)</td>
                </tr>
                <tr> 
                    <td>პასუხი</td>
                    <td>რაოდენობა</td>
                    <td>დელტა</td>
                    <td>%</td>
                </tr>
							<tr class="odd">
						 		<td>15 წამში</td>
					 			<td>0</td>
					 			<td></td>
					 			<td>0%</td>
					 		</tr>
				 			<tr>
						 		<td>30 წამში</td>
					 			<td>0</td>
					 			<td>0</td>
					 			<td>0%</td>
					 		</tr>
				 			<tr class="odd">
						 		<td>45 წამში</td>
					 			<td>0</td>
					 			<td>0</td>
					 			<td>0%</td>
					 		</tr>
				 			<tr>
						 		<td>60 წამში</td>
					 			<td>0</td>
					 			<td>0</td>
					 			<td>0%</td>
					 		</tr>
				 			<tr class="odd">
						 		<td>75 წამში</td>
					 			<td>0</td>
					 			<td>0</td>
					 			<td>0%</td>
					 		</tr>
					 		<tr>
						 		<td>90 წამში</td>
					 			<td>0</td>
					 			<td>0</td>
					 			<td>0%</td>
					 		</tr>
					 		<tr class="odd">
						 		<td>90+ წამში</td>
					 			<td>0</td>
					 			<td>0</td>
					 			<td>100%</td>
					 		</tr>
							</tbody>
              </table>
           
	</div>
</body>
</html>